﻿@model List<UserRole>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>用户角色管理</title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@4.6.0/dist/css/bootstrap.min.css" rel="stylesheet">
    <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
</head>
<body>
    @if (TempData["Message"] != null)
    {
        <script>alert('@Html.Raw(TempData["Message"])');</script>
    }

    <div class="container mt-5">
        <div class="row">
            <div class="col-md-12">
                <div class="card">
                    <div class="card-header bg-primary text-white">
                        用户角色管理
                    </div>
                    <div class="card-body">
                        <table class="table table-striped">
                            <thead class="bg-primary text-white">
                                <tr>
                                    <th>用户ID</th>
                                    <th>用户名</th>
                                    <th>用户账号</th>
                                    <th>角色名</th>
                                    <th>操作</th>
                                </tr>
                            </thead>
                            <tbody>
                                @foreach (var item in Model)
                                {
                                    <tr>
                                        <td>@item.user_Id</td>
                                        <td>@item.user_name</td>
                                        <td>@item.user_account</td>
                                        <td>@item.role_name</td>
                                        <td>
                                            <button class="btn btn-sm btn-primary" data-toggle="modal" data-target="#editRoleModal" data-userid="@item.user_Id" data-username="@item.user_name">编辑</button>
                                        </td>
                                    </tr>
                                }
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <!-- 修改用户角色的模态窗口 -->
    <div class="modal fade" id="editRoleModal" tabindex="-1" role="dialog" aria-labelledby="editRoleModalLabel" aria-hidden="true">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div class="modal-header bg-primary text-white">
                    <h5 class="modal-title" id="editRoleModalLabel">修改用户角色</h5>
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                        <span aria-hidden="true">&times;</span>
                    </button>
                </div>
                <div class="modal-body">
                    <form asp-controller="UserAndRole" asp-action="UpdateUserRoleSumbit" method="post">
                        <div class="form-group">
                            <label for="editUserName">用户名</label>
                            <input type="text" class="form-control" id="editUserName" name="user_name" readonly>
                        </div>

                        <div class="form-group">
                            <label for="roleSelect">选择角色</label>
                            <select class="form-control" id="roleSelect" name="role_id">
                                <option value="1">教师</option>
                                <option value="2">系主任</option>
                                <option value="3">学院主任</option>
                             </select>
                        </div>
                        <input type="hidden" id="editUserId" name="user_Id"  value="123">
                        <div class="text-center">
                            @*<button type="submit" class="btn btn-primary">保存更改</button>*@
                            <input type="submit" class="btn btn-primary"  value="保存更改"/>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</body>
</html>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@4.6.0/dist/js/bootstrap.bundle.min.js"></script>
<script>
    $('#editRoleModal').on('show.bs.modal', function (event) 
    {
        var button = $(event.relatedTarget); 
        var userId = button.data('userid'); 
        var userName = button.data('username');
        var modal = $(this);
        modal.find('#editUserName').val(userName);
        modal.find('#editUserId').val(userId);
    });
</script>



